{
    "cells": [
        {
            "cell_type": "markdown",
            "metadata": {
                "collapsed": true
            },
            "source": "## What are PixieApps?\n\nPixieApps are Python classes used to write UI elements for your analytics, and they run directly in a Jupyter notebook. [Learn more](https://pixiedust.github.io/pixiedust/pixieapps.html)"
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {
                "collapsed": true
            },
            "outputs": [],
            "source": "# uncomment the following line to install/upgrade the PixieDust library\n# ! pip install pixiedust --user --upgrade\nimport pixiedust"
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": "\n## Hello World\n\nThe following sample PixieApp provides two simple views and their associated routes. The first view (default view) creates a button that, when clicked, will invoke the second view. The second view creates another button that redirects to the first view, and so on and so forth."
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {
                "collapsed": false
            },
            "outputs": [],
            "source": "from pixiedust.display.app import *\n@PixieApp\nclass HelloWorldPixieApp:\n    @route()\n    def main(self):\n        return\"\"\"\n            <input pd_options=\"clicked=true\" type=\"button\" value=\"Click Me\">\n        \"\"\"\n    @route(clicked=\"true\")\n    def _clicked(self):\n        return \"\"\"\n            <input pd_options=\"clicked=false\" type=\"button\" value=\"You Clicked, Now Go back\">\n        \"\"\"\n#run the app\nHelloWorldPixieApp().run(runInDialog='false')"
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": "<hr>\n## Hello World with Data\nThe following sample PixieApp simplifies the mechanics of loading and visualizing data. When run successfully, you’ll see a preview button appear in the same area as your Jupyter input cell. Clicking the button will display the data as a table."
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {
                "collapsed": false
            },
            "outputs": [],
            "source": "from pixiedust.display.app import *\n@PixieApp\nclass HelloWorldPixieAppWithData:\n    @route()\n    def main(self):\n        return\"\"\"\n        <div class=\"row\">\n           <div class=\"col-sm-2\">\n              <input pd_options=\"handlerId=dataframe\"\n                     pd_entity\n                     pd_target=\"target{{prefix}}\"\n                     type=\"button\" value=\"Preview Data\">\n           </div>\n           <div class=\"col-sm-10\" id=\"target{{prefix}}\"/>\n        </div>\n        \"\"\"\n#Create dataframe\ndf = SQLContext(sc).createDataFrame(\n[(2010, 'Camping Equipment', 3, 200),(2010, 'Camping Equipment', 10, 200),(2010, 'Golf Equipment', 1, 240),\n (2010, 'Mountaineering Equipment', 1, 348),(2010, 'Outdoor Protection',2,200),(2010, 'Personal Accessories', 2, 200),\n (2011, 'Camping Equipment', 4, 489),(2011, 'Golf Equipment', 5, 234),(2011, 'Mountaineering Equipment',2, 123),\n (2011, 'Outdoor Protection', 4, 654),(2011, 'Personal Accessories', 2, 234),(2012, 'Camping Equipment', 5, 876),\n (2012, 'Golf Equipment', 5, 200),(2012, 'Mountaineering Equipment', 3, 156),(2012, 'Outdoor Protection', 5, 200),\n (2012, 'Personal Accessories', 3, 345),(2013, 'Camping Equipment', 8, 987),(2013, 'Golf Equipment', 5, 434),\n (2013, 'Mountaineering Equipment', 3, 278),(2013, 'Outdoor Protection', 8, 134),(2013,'Personal Accessories',4, 200)],\n [\"year\",\"zone\",\"unique_customers\", \"revenue\"])\n\n#run the app\nHelloWorldPixieAppWithData().run(df, runInDialog='false')"
        }
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "Python 2 with Spark 2.0",
            "language": "python",
            "name": "python2-spark20"
        },
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 2
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython2",
            "version": "2.7.11"
        }
    },
    "nbformat": 4,
    "nbformat_minor": 0
}